using System;
using NUnit.Framework;
using Sedge.Core.Configuration;
using Sedge.Core.Configuration.Property;

namespace Sedge.Tests.Configuration
{
	[TestFixture]
	public class PropertyResolverTest
	{
		[Test]
		public void ResolveWithoutParent()
		{
			const string testString = "Test string";
			string resultString = PropertyResolver.ResolveValue(null, testString);

			Assert.IsTrue(testString.Equals(resultString));
		}

		[Test]
		public void ResolveWithoutNullString()
		{
			ReportableObject reportableObject = new ReportableObject();
			string resultString = PropertyResolver.ResolveValue(reportableObject, null);
			Assert.IsTrue(String.IsNullOrEmpty(resultString));
		}

		[Test]
		public void ResolveWithParent()
		{
			const string valueString = "value1";

			ReportableObject reportableObject = new ReportableObject();
			reportableObject.Properties["value.one"] = valueString;

			const string testString = "${value.one}";
			string resultString = PropertyResolver.ResolveValue(reportableObject, testString);

			Assert.IsTrue(resultString.Equals(valueString));
		}

		[Test]
		public void ResolveTwoVariblesWithParent()
		{
			const string valueString1 = "value1";
			const string valueString2 = "value2";

			ReportableObject reportableObject = new ReportableObject();
			reportableObject.Properties["value.one"] = valueString1;
			reportableObject.Properties["value.two"] = valueString2;

			const string testString = "A ${value.one} is not ${value.two}.";
			string resultString = PropertyResolver.ResolveValue(reportableObject, testString);

			Assert.IsTrue(resultString.Equals("A value1 is not value2."));
		}

		[Test]
		public void ResolveBlobalVariable()
		{
			const string valueString = "value1";

			ReportableObject reportableObject = new ReportableObject();
			ReportableObject.GlobalProperties["global.value"] = valueString;

			const string testString = "${global.value}";
			string resultString = PropertyResolver.ResolveValue(reportableObject, testString);

			Assert.IsTrue(resultString.Equals(valueString));
		}

	}
}